﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Configuration;
using System.Data;
namespace Piao
{
    static class Configurations
    {
        static Configurations()
        {
            var section = (AppSettingsSection)config.GetSection("appSettings");
            appSettings = section;
        }

        static Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
        static AppSettingsSection appSettings;

        public static void Save()
        {
            try
            {
                config.Save(ConfigurationSaveMode.Modified, true);
                ConfigurationManager.RefreshSection("appSettings");
            }
            catch (System.Configuration.ConfigurationErrorsException)
            {

            }

        }

        private static void Update(string key, string value)
        {
            if (!appSettings.Settings.AllKeys.Contains(key))
                appSettings.Settings.Add(key, value);
            else
                appSettings.Settings[key].Value = value;
        }

        public static string txt_userFromStation
        {
            get
            {
                return appSettings.Settings["txt_userFromStation"].Value;
            }
            set
            {
                Update("txt_userFromStation", value);
            }
        }

        public static string txt_userToStation
        {
            get
            {
                return appSettings.Settings["txt_userToStation"].Value;
            }
            set
            {
                Update("txt_userToStation", value);
            }
        }

        public static string txt_userTrains
        {
            get
            {
                return appSettings.Settings["txt_userTrains"].Value;
            }
            set
            {
                Update("txt_userTrains", value);
            }
        }

        public static string chk_userSeatTypes
        {
            get
            {
                return appSettings.Settings["chk_userSeatTypes"].Value;
            }
            set
            {
                Update("chk_userSeatTypes", value);
            }
        }
    }



}
